﻿<%@ WebHandler Language="C#" Class="lists" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;

public class lists : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string query = HttpContext.Current.Request.Params["page"];
        string goods_ids = HttpContext.Current.Request.Params["goods_ids"];


        if (string.IsNullOrEmpty(query))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "商品列表";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {
            var result = bll.S_Goods.Where(p => p.IsLock != true);//全部.ToList();

            var _myresult = result.ToList();

            List<progood> list = new List<progood>();
            foreach (var x in _myresult)
            {
                progood mygood = new progood();
                mygood.id = x.GID;
                mygood.type = "normal";
                mygood.title = x.GName;
                mygood.image = methods.GetImgs(x.GImg)[0].ToString();
                mygood.price =Convert.ToDecimal(x.GPrice);  //购买的价格可以根据级别显示不同价格 处理
                mygood.sales = x.GSales;
                list.Add(mygood);
            };

            var total =result.Count();
            var per_page = 10;
            var current_page=1;
            var last_page=1;

            var data = new { total,per_page,current_page, last_page,data=list};
            context.Response.Write(JsonConvert.SerializeObject(new { code,msg,time,data}));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }

    public bool IsReusable {
        get {
            return false;
        }
    }

    public class progood
    {
        public int id { get;  set; }
        public string type { get; set; }
        public string title { get; set; }
        public string image { get; set; }
        public decimal price { get; set; }
        public int? sales { get; set; }

    }


}